<%--
  Created by IntelliJ IDEA.
  User: 75616
  Date: 2018/3/20
  Time: 17:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>pay</title>
    <style>
        .btn {
            width: 9rem;
            height: 2rem;
            margin: 3rem auto;
            color: white;
            font-size: 14px;
            background-color: #01AAED;
        }
    </style>
</head>
<body>
ProductId: <input type="number" class="j_productId"> <br>
AddressId: <input type="number" class="j_addressId"> <br>
CouponId: <input type="number" class="j_couponId"> <br>
<button class="btn" onclick="GFunc.pay()">支付1分钱</button>
<script src="${pageContext.request.contextPath}/js/common/jquery.1.11.3.min.js"></script>
<script type="text/javascript">
    var GFunc = {
        pay: function () {
            var data = {
                productId: $('.j_productId').val(),
                couponId: $('.j_couponId').val(),
                addressId: $('.j_addressId').val()
            }
            $.post('/api/product/order/get_prepay_info.do', data, function (data) {
                if (data.code != 200) {
                    alert(data.message);
                    return;
                }
                WeixinJSBridge.invoke('getBrandWCPayRequest', data.result, function (res) {
                    if (res.err_msg == 'get_brand_wcpay_request:ok') {
                        alert('支付成功');
                    } else if (res.err_msg == 'get_brand_wcpay_request:cancel') {
                        alert('您取消了支付!即将返回列表页.');
                    } else {
                        var msg = '支付失败,请重新支付.';
                        alert(msg);
                    }
                });
            });
        }
    }
</script>
</body>
</html>
